﻿using lBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class JuMinController : ControllerBase, ljuMinBll
    {
        public JuMinController(ljuMinBll bll,IWebHostEnvironment web)
        {
            Bll = bll;
            Web = web;
        }

        public ljuMinBll Bll { get; }
        public IWebHostEnvironment Web { get; }

        [HttpPost]
        public dynamic Img(IFormFile file)
        {
            string n = DateTime.Now.ToString("yyyyMMddhhmmss");
            string path=Web.WebRootPath +@"\img\"+ n+file.FileName;
            using (FileStream fs = System.IO.File.Create(path))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return "/img/" + n + file.FileName;
        }

        [HttpPost]
        public Task<int> Add(JuMin juMin)
        {
           return Bll.Add(juMin);
        }

        [HttpDelete]
        public Task<int> Delete(int id)
        {
           return Bll.Delete(id);
        }

        [HttpDelete]
        public Task<int> Delted(string idstring)
        {
            return Bll.Delted(idstring);
        }
        [HttpGet]
        public dynamic Find(int id)
        {
            return Bll.Find(id);
        }

        [HttpGet]
        public dynamic Show(string? name, int? type, int index, int size)
        {
            return Bll.Show(name, type, index, size);
        }

        [HttpPut]
        public Task<int> Update(JuMin juMin)
        {
           return Bll.Update(juMin);
        }

        [HttpGet]
        public Task<int> Updstate(string idstring)
        {
            return Bll.Updstate(idstring);
        }

        [HttpGet]
        public dynamic Xia()
        {
            return Bll.Xia();
        }
    }
}
